#!/bin/sh

VERSION=0.2

help()
{
	echo ""
	echo "Usage is: configure [--prefix=PREFIX] [--cecil=PATH_TO_CECIL_DLL]"
	echo ""
}

prefix=/usr/local
cecilbin=

while [ $# -ne 0 ]; do
  case $1 in
    --help)
    	help
    	exit 0
	;;
    --prefix=*)
    	prefix=`echo $1 | sed 's/--prefix=//'`;
	shift
	;;
    --prefix)
        shift
	prefix="$1"
	shift
	;;
    --cecil=*)
    	cecilbin=`echo $1 | sed 's/--cecil=//'`;
	shift
	;;
    *)
	echo Unknown option: $1
	help
	shift
  esac
done

if test -z "$cecilbin"; then
	cecilbin=`pkg-config --variable=Libraries mono-cecil`
fi

if test -z "$cecilbin"; then
	echo "Cecil is not installed."
	if test -f Mono.Cecil.dll; then
		echo "Using packaged Mono.Cecil.dll."
	else
		echo "No Mono.Cecil.dll found, use --cecil=/path/to/Mono.Cecil.dll option."
		exit 1
	fi
else
	# copy Mono.Cecil here
	echo "Using Cecil from $cecilbin."
	cp $cecilbin .
fi

echo "prefix=$prefix" > config.make
echo "VERSION=$VERSION" >> config.make
echo "class Constants {public const string Version=\"$VERSION\";}"  >Constants.cs

echo "#!/bin/sh" > monocov
echo "exec mono $prefix/lib/monocov/monocov.exe \$@" >> monocov
chmod +x monocov

echo ""
echo "MonoCov module configured"
echo ""
echo "     Prefix:           $prefix"
echo "     Version:          $VERSION"
echo ""

exit 0;
